| 0 | 2 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,63 @@ |
| 0 |
+package examples |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "io/ioutil" |
|
| 4 |
+ "os" |
|
| 5 |
+ "path/filepath" |
|
| 6 |
+ |
|
| 7 |
+ "testing" |
|
| 8 |
+ |
|
| 9 |
+ kubeapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api" |
|
| 10 |
+ "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
|
| 11 |
+ |
|
| 12 |
+ "github.com/openshift/origin/pkg/api/latest" |
|
| 13 |
+ buildapi "github.com/openshift/origin/pkg/build/api" |
|
| 14 |
+ configapi "github.com/openshift/origin/pkg/config/api" |
|
| 15 |
+ templateapi "github.com/openshift/origin/pkg/template/api" |
|
| 16 |
+) |
|
| 17 |
+ |
|
| 18 |
+func TestExamples(t *testing.T) {
|
|
| 19 |
+ expected := map[string]runtime.Object{
|
|
| 20 |
+ "guestbook/template.json": &templateapi.Template{},
|
|
| 21 |
+ "hello-openshift/hello-pod.json": &kubeapi.Pod{},
|
|
| 22 |
+ "simple-ruby-app/buildcfg/buildcfg.json": &buildapi.BuildConfig{},
|
|
| 23 |
+ "simple-ruby-app/buildinvoke/pushevent.json": nil, // Skip. |
|
| 24 |
+ "simple-ruby-app/registry_config/registry_config.json": &configapi.Config{},
|
|
| 25 |
+ "simple-ruby-app/template/template.json": &templateapi.Template{},
|
|
| 26 |
+ } |
|
| 27 |
+ |
|
| 28 |
+ files := []string{}
|
|
| 29 |
+ err := filepath.Walk(".", func(path string, f os.FileInfo, err error) error {
|
|
| 30 |
+ if filepath.Ext(path) == ".json" {
|
|
| 31 |
+ files = append(files, path) |
|
| 32 |
+ } |
|
| 33 |
+ return err |
|
| 34 |
+ }) |
|
| 35 |
+ if err != nil {
|
|
| 36 |
+ t.Errorf("%v", err)
|
|
| 37 |
+ } |
|
| 38 |
+ |
|
| 39 |
+ for _, file := range files {
|
|
| 40 |
+ expectedObject, ok := expected[file] |
|
| 41 |
+ if !ok {
|
|
| 42 |
+ t.Errorf("No test case defined for example JSON file '%v'", file)
|
|
| 43 |
+ continue |
|
| 44 |
+ } |
|
| 45 |
+ if expectedObject == nil {
|
|
| 46 |
+ continue |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ jsonData, _ := ioutil.ReadFile(file) |
|
| 50 |
+ if err := latest.Codec.DecodeInto(jsonData, expectedObject); err != nil {
|
|
| 51 |
+ t.Errorf("Unexpected error while decoding example JSON file '%v': %v", file, err)
|
|
| 52 |
+ } |
|
| 53 |
+ } |
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+func TestReadme(t *testing.T) {
|
|
| 57 |
+ path := "../README.md" |
|
| 58 |
+ _, err := ioutil.ReadFile(path) |
|
| 59 |
+ if err != nil {
|
|
| 60 |
+ t.Fatalf("Unable to read file: %v", err)
|
|
| 61 |
+ } |
|
| 62 |
+} |
| ... | ... |
@@ -1,5 +1,7 @@ |
| 1 | 1 |
{
|
| 2 | 2 |
"id": "build100", |
| 3 |
+ "kind": "BuildConfig", |
|
| 4 |
+ "apiVersion": "v1beta1", |
|
| 3 | 5 |
"desiredInput": |
| 4 | 6 |
{
|
| 5 | 7 |
"type": "docker", |
| ... | ... |
@@ -7,6 +9,5 @@ |
| 7 | 7 |
"imageTag": "openshift/origin-ruby-sample", |
| 8 | 8 |
"registry": "127.0.0.1:5000" |
| 9 | 9 |
}, |
| 10 |
- |
|
| 11 | 10 |
"secret": "secret101" |
| 12 | 11 |
} |
| ... | ... |
@@ -1,8 +1,10 @@ |
| 1 | 1 |
{
|
| 2 |
+ "id": "docker-registry-config", |
|
| 3 |
+ "kind": "Config", |
|
| 2 | 4 |
"apiVersion": "v1beta1", |
| 3 | 5 |
"creationTimestamp": "2014-09-18T18:28:38-04:00", |
| 6 |
+ "name": "docker-registry-config", |
|
| 4 | 7 |
"description": "Creates a private docker registry", |
| 5 |
- "id": "docker-registry-config", |
|
| 6 | 8 |
"items": [ |
| 7 | 9 |
{
|
| 8 | 10 |
"apiVersion": "v1beta1", |
| ... | ... |
@@ -55,7 +57,5 @@ |
| 55 | 55 |
"name": "registryController" |
| 56 | 56 |
} |
| 57 | 57 |
} |
| 58 |
- ], |
|
| 59 |
- "kind": "Config", |
|
| 60 |
- "name": "docker-registry-config" |
|
| 58 |
+ ] |
|
| 61 | 59 |
} |