-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nicolastakashi/development
[FEAT] adding unit tests
- Loading branch information
Showing
9 changed files
with
276 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dashboardloader | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestLoadInvalidPath(t *testing.T) { | ||
dashboards, err := Load("./dev/blabla") | ||
|
||
if err == nil { | ||
t.Fatal("load an path file must return an error") | ||
} | ||
|
||
if len(dashboards) > 0 { | ||
t.Fatal("load an invalid path must not return a dashboard struct") | ||
} | ||
} | ||
|
||
func TestLoadInvalidFile(t *testing.T) { | ||
dashboards, err := Load("./testdata/invalid") | ||
|
||
if err == nil { | ||
t.Fatal("load an invalid json file must return an error") | ||
} | ||
|
||
if len(dashboards) > 0 { | ||
t.Fatal("load an invalid json file must not return a dashboard struct") | ||
} | ||
} | ||
|
||
func TestLoadValidFile(t *testing.T) { | ||
dashboards, err := Load("./testdata/valid") | ||
|
||
if err != nil { | ||
t.Fatal("load an valid json file must not return an error") | ||
} | ||
|
||
if len(dashboards) == 0 { | ||
t.Fatal("load an valid json file must return a dashboard struct") | ||
} | ||
} | ||
|
||
func TestLoadEmptyFile(t *testing.T) { | ||
dashboards, err := Load("./testdata/empty") | ||
|
||
if err == nil { | ||
t.Fatal("load an empty json file must return an error") | ||
} | ||
|
||
if len(dashboards) > 0 { | ||
t.Fatal("load an empty json file must not return a dashboard struct") | ||
} | ||
} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"checklist": "XXX", | ||
"notes": "" | ||
} | ||
{ "checklist": "XXX", | ||
"notes": "" | ||
} | ||
{ | ||
"checklist": "XXX", | ||
"notes": "" | ||
} | ||
{ | ||
"checklist": "XXX", | ||
"notes": "" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
{ | ||
"annotations": { | ||
"list": [ | ||
{ | ||
"builtIn": 1, | ||
"datasource": "-- Grafana --", | ||
"enable": true, | ||
"hide": true, | ||
"iconColor": "rgba(0, 211, 255, 1)", | ||
"name": "Annotations & Alerts", | ||
"target": { | ||
"limit": 100, | ||
"matchAny": false, | ||
"tags": [], | ||
"type": "dashboard" | ||
}, | ||
"type": "dashboard" | ||
} | ||
] | ||
}, | ||
"editable": true, | ||
"gnetId": null, | ||
"graphTooltip": 0, | ||
"links": [], | ||
"panels": [ | ||
{ | ||
"datasource": null, | ||
"fieldConfig": { | ||
"defaults": { | ||
"color": { | ||
"mode": "palette-classic" | ||
}, | ||
"custom": { | ||
"axisLabel": "", | ||
"axisPlacement": "auto", | ||
"barAlignment": 0, | ||
"drawStyle": "line", | ||
"fillOpacity": 17, | ||
"gradientMode": "opacity", | ||
"hideFrom": { | ||
"legend": false, | ||
"tooltip": false, | ||
"viz": false | ||
}, | ||
"lineInterpolation": "smooth", | ||
"lineStyle": { | ||
"fill": "solid" | ||
}, | ||
"lineWidth": 1, | ||
"pointSize": 3, | ||
"scaleDistribution": { | ||
"type": "linear" | ||
}, | ||
"showPoints": "auto", | ||
"spanNulls": false, | ||
"stacking": { | ||
"group": "A", | ||
"mode": "none" | ||
}, | ||
"thresholdsStyle": { | ||
"mode": "off" | ||
} | ||
}, | ||
"mappings": [], | ||
"thresholds": { | ||
"mode": "absolute", | ||
"steps": [ | ||
{ | ||
"color": "green", | ||
"value": null | ||
} | ||
] | ||
}, | ||
"unit": "reqps" | ||
}, | ||
"overrides": [ | ||
{ | ||
"matcher": { | ||
"id": "byName", | ||
"options": "requests per second" | ||
}, | ||
"properties": [ | ||
{ | ||
"id": "color", | ||
"value": { | ||
"fixedColor": "yellow", | ||
"mode": "fixed" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"gridPos": { | ||
"h": 9, | ||
"w": 12, | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"id": 2, | ||
"options": { | ||
"legend": { | ||
"calcs": [], | ||
"displayMode": "list", | ||
"placement": "bottom" | ||
}, | ||
"tooltip": { | ||
"mode": "single" | ||
} | ||
}, | ||
"targets": [ | ||
{ | ||
"exemplar": true, | ||
"expr": "sum(rate(http_requests_total{handler=~\"query.+\", job=\"thanos_query\"}[5m]))", | ||
"interval": "", | ||
"legendFormat": "requests per second", | ||
"refId": "A" | ||
} | ||
], | ||
"title": "Http Requests Total", | ||
"type": "timeseries" | ||
} | ||
], | ||
"schemaVersion": 30, | ||
"style": "dark", | ||
"tags": [], | ||
"templating": { | ||
"list": [] | ||
}, | ||
"time": { | ||
"from": "now-2d", | ||
"to": "now" | ||
}, | ||
"timepicker": {}, | ||
"timezone": "", | ||
"title": "dash_two", | ||
"uid": "dash_two", | ||
"version": 1 | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gitmanager | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetInvalidBranch(t *testing.T) { | ||
r := &Repository{ | ||
Url: "https://github.com/nicolastakashi/gitana", | ||
Path: "/tmp/gitana/test", | ||
Branch: "invalid", | ||
} | ||
|
||
_, err := r.Get(context.TODO()) | ||
|
||
assert.NotNil(t, err, "Get invalid branch MUST return an error") | ||
assert.Equal(t, err.Error(), "reference not found") | ||
} | ||
|
||
func TestGetValidBranch(t *testing.T) { | ||
r := &Repository{ | ||
Url: "https://github.com/nicolastakashi/gitana", | ||
Path: "/tmp/gitana/test", | ||
Branch: "main", | ||
} | ||
|
||
_, err := r.Get(context.TODO()) | ||
|
||
assert.Nil(t, err, "Get valid branch MUST not return an error") | ||
} | ||
|
||
func TestGetAlreadyExistingRepo(t *testing.T) { | ||
r := &Repository{ | ||
Url: "https://github.com/nicolastakashi/gitana", | ||
Path: "/tmp/gitana/test/pull", | ||
Branch: "main", | ||
} | ||
|
||
_, err := r.Get(context.TODO()) | ||
|
||
assert.Nil(t, err, "Get valid branch MUST not return an error") | ||
|
||
_, err = r.Get(context.TODO()) | ||
|
||
assert.Nil(t, err, "Get valid branch MUST not return an error") | ||
} |