Skip to content

Commit

Permalink
remove duplication
Browse files Browse the repository at this point in the history
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
  • Loading branch information
bennyz committed Dec 19, 2023
1 parent 0c8f80d commit de18036
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions cmd/openstack-populator/openstack-populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func setupMockServer() (*httptest.Server, string, int, error) {
mux := http.NewServeMux()

port := listener.Addr().(*net.TCPAddr).Port
identityServerURL := fmt.Sprintf("http://localhost:%d", port)
baseURL := fmt.Sprintf("http://localhost:%d", port)

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
Expand All @@ -36,7 +36,7 @@ func setupMockServer() (*httptest.Server, string, int, error) {
}
]
}
}`, identityServerURL)
}`, baseURL)
fmt.Fprint(w, response)
})

Expand All @@ -48,10 +48,8 @@ func setupMockServer() (*httptest.Server, string, int, error) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("X-Subject-Token", "MIIFvgY")
w.WriteHeader(http.StatusCreated)
identityPublicURL := fmt.Sprintf("http://localhost:%d/v3/", port)
identityAdminURL := fmt.Sprintf("http://localhost:%d/v3/", port)
identityInternalURL := fmt.Sprintf("http://localhost:%d/v3/", port)
imageServiceURL := fmt.Sprintf("http://localhost:%d/v2/images", port)
identityServer := fmt.Sprintf("%s/v3/", fmt.Sprintf(baseURL, port))
imageServiceURL := fmt.Sprintf("%s/v2/images", fmt.Sprintf(baseURL, port))

response := fmt.Sprintf(`{
"token": {
Expand Down Expand Up @@ -113,9 +111,9 @@ func setupMockServer() (*httptest.Server, string, int, error) {
"issued_at": "201406-10T20:55:16.806027Z"
}
}`,
identityPublicURL,
identityAdminURL,
identityInternalURL,
identityServer,
identityServer,
identityServer,
imageServiceURL)

fmt.Fprint(w, response)
Expand All @@ -126,7 +124,7 @@ func setupMockServer() (*httptest.Server, string, int, error) {

server.Start()

return server, identityServerURL, port, nil
return server, baseURL, port, nil
}

func TestPopulate(t *testing.T) {
Expand Down Expand Up @@ -165,7 +163,7 @@ func TestPopulate(t *testing.T) {
t.Fatalf("Failed to read file: %v", err)
}

if string(content) != "mock_data\n" {
if string(content) != "m2ock_data\n" {
t.Errorf("Expected %s, got %s", "mock_data\n", string(content))
}

Expand Down

0 comments on commit de18036

Please sign in to comment.