Browse Source

update tests

esell 1 year ago
parent
commit
2b72b30908
1 changed files with 38 additions and 1 deletions
  1. 38
    1
      main_test.go

+ 38
- 1
main_test.go View File

@@ -79,7 +79,7 @@ func TestUploadHandler(t *testing.T) {
79 79
 }
80 80
 
81 81
 func TestDisplayHandler(t *testing.T) {
82
-	config := conf{ListenPort: "9666", ShieldURL: "blah.com"}
82
+	config := conf{ListenPort: "9666", ShieldURL: "https://img.shields.io/badge"}
83 83
 	displayHandle := displayHandler(config)
84 84
 
85 85
 	// GET
@@ -98,4 +98,41 @@ func TestDisplayHandler(t *testing.T) {
98 98
 		t.Errorf("displayHandler POST returned %v, should be %v", w.Code, http.StatusMethodNotAllowed)
99 99
 	}
100 100
 
101
+	// real GET - should fail (500)
102
+	req, _ = http.NewRequest("GET", "?repo=blah", nil)
103
+	w = httptest.NewRecorder()
104
+	displayHandle.ServeHTTP(w, req)
105
+	if w.Code != http.StatusInternalServerError {
106
+		t.Errorf("displayHandler GET returned %v, should be %v", w.Code, http.StatusInternalServerError)
107
+	}
108
+
109
+	// real GET - should work
110
+	// stage test files
111
+
112
+	origCvr, err := os.Open("samples/coverage.out")
113
+	if err != nil {
114
+		t.Errorf("error opening up sample coverage.out: %s", err)
115
+	}
116
+	defer origCvr.Close()
117
+	if err := os.MkdirAll("blah", 0755); err != nil {
118
+		t.Errorf("error creating directory for %s: %s\n", "blah", err)
119
+	}
120
+	copyCvr, err := os.Create("blah/coverage.out")
121
+	if err != nil {
122
+		t.Errorf("error creating copy of coverage.out: %s", err)
123
+	}
124
+	_, err = io.Copy(copyCvr, origCvr)
125
+	if err != nil {
126
+		t.Errorf("error writing copy of coverage.out: %s", err)
127
+	}
128
+	if err := copyCvr.Close(); err != nil {
129
+		t.Errorf("error saving copy of coverage.out: %s", err)
130
+	}
131
+	req, _ = http.NewRequest("GET", "?repo=blah", nil)
132
+	w = httptest.NewRecorder()
133
+	displayHandle.ServeHTTP(w, req)
134
+	if w.Code != http.StatusOK {
135
+		t.Errorf("displayHandler GET returned %v, should be %v", w.Code, http.StatusOK)
136
+	}
137
+
101 138
 }