You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/08/28 21:01:40 UTC

[GitHub] [trafficcontrol] jhg03a commented on a change in pull request #3567: New fakeOrigin testing tool

jhg03a commented on a change in pull request #3567:
URL: https://github.com/apache/trafficcontrol/pull/3567#discussion_r479532558



##########
File path: test/fakeOrigin/endpoint/endpoint.go
##########
@@ -0,0 +1,216 @@
+package endpoint
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"path/filepath"
+	"strings"
+)
+
+// DefaultConfigFile is the default configuration file path
+const DefaultConfigFile = "config.json"
+
+// DefaultOutputDirectory is the default output directory for generated content
+const DefaultOutputDirectory = "./out"
+
+// DefaultHTTPSKeyFile is the default path to the SSL key
+const DefaultHTTPSKeyFile = "server.key"
+
+// DefaultHTTPSCertFile is the default path to the SSL certificate
+const DefaultHTTPSCertFile = "server.cert"
+
+// ServerInfo contains relevant info for serving content
+type ServerInfo struct {
+	HTTPListeningPort  int    `json:"http_port"`
+	HTTPSListeningPort int    `json:"https_port"`
+	SSLCert            string `json:"ssl_cert"`
+	SSLKey             string `json:"ssl_key"`
+	BindingAddress     string `json:"binding_address"`
+	CrossdomainFile    string `json:"crossdomain_xml_file"`
+}
+
+// Endpoint defines all kinds of endpoints to be served
+type Endpoint struct {
+	ID              string              `json:"id"`
+	DiskID          string              `json:"override_disk_id,omitempty"`
+	Source          string              `json:"source"`
+	OutputDirectory string              `json:"outputdir,omitifempty"`
+	EndpointType    Type                `json:"type"`
+	ManualCommand   []string            `json:"manual_command,omitempty"`
+	DefaultHeaders  map[string][]string `json:"default_headers,omitempty"`
+	NoCache         bool                `json:"no_cache,omitempty"`
+	ABRManifests    []string            `json:"abr_manifests,omitempty"`
+}
+
+// Config defines the application configuration
+type Config struct {
+	ServerConf ServerInfo `json:"server"`
+	Endpoints  []Endpoint `json:"endpoints"`
+}
+
+func contains(args []string, param string) bool {
+	for _, str := range args {
+		if strings.Contains(str, param) {
+			return true
+		}
+	}
+	return false
+}
+
+func replace(tokenDict map[string]string, input string) string {
+	for k, v := range tokenDict {
+		input = strings.Replace(input, k, v, -1)
+	}
+	return input
+}
+
+// DefaultConfig generates a basic default configuration
+func DefaultConfig() Config {
+	return Config{
+		ServerConf: ServerInfo{
+			HTTPListeningPort:  8080,
+			HTTPSListeningPort: 8443,
+			SSLCert:            DefaultHTTPSCertFile,
+			SSLKey:             DefaultHTTPSKeyFile,
+			BindingAddress:     "",
+			CrossdomainFile:    "./example/crossdomain.xml",
+		},
+		Endpoints: []Endpoint{
+			{
+				ID:              "SampleFile",
+				Source:          "./example/video/kelloggs.mp4",
+				OutputDirectory: DefaultOutputDirectory,
+				EndpointType:    Static,
+			},
+			{
+				ID:              "SampleDirectory",
+				Source:          "./example/video/",
+				OutputDirectory: DefaultOutputDirectory,
+				EndpointType:    Dir,
+			},
+		},
+	}
+}
+
+// WriteConfig saves a fakeOrigin config as a pretty-printed json file
+func WriteConfig(cfg Config, path string) error {
+	bts, err := json.MarshalIndent(cfg, "", "\t")
+	if err != nil {
+		return errors.New("marshalling JSON: " + err.Error())
+	}
+	if err = ioutil.WriteFile(path, bts, 0755); err != nil {

Review comment:
       Resolved via commit

##########
File path: test/fakeOrigin/shard.sh
##########
@@ -0,0 +1,86 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#!/bin/bash

Review comment:
       Resolved via commit




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org