Created
March 27, 2018 19:46
-
-
Save dymurray/a7529568534dff9c866a2dff22e6fe59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Copyright (c) 2018 Red Hat, Inc. | |
// | |
// Licensed 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. | |
// | |
package adapters | |
import ( | |
"fmt" | |
"net/http" | |
"net/http/httptest" | |
"net/url" | |
"strings" | |
"testing" | |
ft "github.com/stretchr/testify/assert" | |
) | |
var Images = []string{"satoshi/nakamoto", "foo/bar", "paul/atreides"} | |
func TestOpenShiftName(t *testing.T) { | |
ocpa := OpenShiftAdapter{} | |
ft.Equal(t, ocpa.RegistryName(), "openshift", "openshift name does not match `openshift`") | |
} | |
func TestOpenShiftGetImageNames(t *testing.T) { | |
ocpa := OpenShiftAdapter{} | |
ocpa.Config.Images = Images | |
imagesFound, err := ocpa.GetImageNames() | |
if err != nil { | |
t.Fatal("Error: ", err) | |
} | |
ft.Equal(t, imagesFound, Images, "image names returned did not match expected config") | |
} | |
func TestOpenShiftFetchSpecs(t *testing.T) { | |
serv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
if r.Method != "GET" { | |
fmt.Println("HERE!") | |
t.Errorf("Expected `GET` request, got `%s`", r.Method) | |
} | |
if strings.HasSuffix(r.URL.EscapedPath(), "/v2/") { | |
fmt.Println("HERE") | |
w.Header().Add("Www-Authenticate", "Bearer realm=\"http://127.0.0.1:54321/v2/auth/realms/foo-docker-v2/auth\",service=\"docker-registry\"") | |
} | |
if strings.Contains(r.URL.EscapedPath(), "manifests") { | |
fmt.Println("HERE323") | |
} | |
})) | |
serv.Config.Addr = "http://127.0.0.1:54321" | |
fmt.Println(serv.Config.Addr) | |
fmt.Println(serv.URL) | |
serv.Start() | |
fmt.Println(serv.URL) | |
url, err := url.Parse(serv.URL) | |
if err != nil { | |
t.Fatal("Error: ", err) | |
} | |
ocpa := OpenShiftAdapter{ | |
Config: Configuration{ | |
URL: url, | |
User: "satoshi", | |
Pass: "nakamoto", | |
Images: Images, | |
}, | |
} | |
imageNames, err := ocpa.GetImageNames() | |
specs, err := ocpa.FetchSpecs(imageNames) | |
if err != nil { | |
t.Fatal("Error: ", err) | |
} | |
if specs != nil { | |
t.Fatal("ERE") | |
} | |
// ft.Equal(t, imagesFound, images, "image names returned did not match expected config") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment