func TestResolve(t *testing.T) { tests := []struct { name string cfg AppConfig components app.ComponentReferences expectedErr string }{ { name: "Resolver error", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ Value: "mysql:invalid", Resolver: app.DockerRegistryResolver{ Client: dockerregistry.NewClient(), }, })}, expectedErr: `tag "invalid" has not been set`, }, { name: "Successful mysql builder", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ Value: "mysql", Match: &app.ComponentMatch{ Builder: true, }, })}, expectedErr: "", }, { name: "Unable to build source code", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ Value: "mysql", ExpectToBuild: true, })}, expectedErr: "no resolver", }, { name: "Successful docker build", cfg: AppConfig{ Strategy: "docker", }, components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ Value: "mysql", ExpectToBuild: true, })}, expectedErr: "", }, } for _, test := range tests { err := test.cfg.resolve(test.components) if err != nil { if !strings.Contains(err.Error(), test.expectedErr) { t.Errorf("%s: Invalid error: Expected %s, got %v", test.name, test.expectedErr, err) } } else if len(test.expectedErr) != 0 { t.Errorf("%s: Expected %s error but got none", test.name, test.expectedErr) } } }
func TestEnsureHasSource(t *testing.T) { tests := []struct { name string cfg AppConfig components app.ComponentReferences repositories []*app.SourceRepository expectedErr string }{ { name: "One requiresSource, multiple repositories", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ ExpectToBuild: true, }), }, repositories: app.MockSourceRepositories(), expectedErr: "there are multiple code locations provided - use one of the following suggestions", }, { name: "Multiple requiresSource, multiple repositories", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ ExpectToBuild: true, }), app.ComponentReference(&app.ComponentInput{ ExpectToBuild: true, }), }, repositories: app.MockSourceRepositories(), expectedErr: "Use '[image]~[repo]' to declare which code goes with which image", }, { name: "One requiresSource, no repositories", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ ExpectToBuild: true, }), }, repositories: []*app.SourceRepository{}, expectedErr: "you must specify a repository via --code", }, { name: "Multiple requiresSource, no repositories", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ ExpectToBuild: true, }), app.ComponentReference(&app.ComponentInput{ ExpectToBuild: true, }), }, repositories: []*app.SourceRepository{}, expectedErr: "you must provide at least one source code repository", }, { name: "Successful - one repository", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ ExpectToBuild: false, }), }, repositories: []*app.SourceRepository{app.MockSourceRepositories()[0]}, expectedErr: "", }, { name: "Successful - no requiresSource", components: app.ComponentReferences{ app.ComponentReference(&app.ComponentInput{ ExpectToBuild: false, }), }, repositories: app.MockSourceRepositories(), expectedErr: "", }, } for _, test := range tests { err := test.cfg.ensureHasSource(test.components, test.repositories) if err != nil { if !strings.Contains(err.Error(), test.expectedErr) { t.Errorf("%s: Invalid error: Expected %s, got %v", test.name, test.expectedErr, err) } } else if len(test.expectedErr) != 0 { t.Errorf("%s: Expected %s error but got none", test.name, test.expectedErr) } } }