Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[add] CI #47

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: go-ci

on: [push]

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: set up
uses: actions/setup-go@v2
with:
go-version: ^1.16
id: go
- name: check out
uses: actions/checkout@v2
- name: Cache
uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

build:
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: build
run: go build ./...

test:
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: test
run: go test ./speedtest -v

lint:
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.29
4 changes: 2 additions & 2 deletions speedtest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestFetchServerList(t *testing.T) {
if len(serverList.Servers) == 0 {
t.Errorf("Failed to fetch server list.")
}
if serverList.Servers[0].Country != "Japan" {
t.Errorf("got unexpected country '%v', expected 'Japan'", serverList.Servers[0].Country)
if len(serverList.Servers[0].Country) == 0 {
t.Errorf("got unexpected country name '%v'", serverList.Servers[0].Country)
}
}

Expand Down
25 changes: 15 additions & 10 deletions speedtest/user_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package speedtest

import "testing"
import "strings"
import (
"strconv"
"strings"
"testing"
)

func TestFetchUserInfo(t *testing.T) {
user, err := FetchUserInfo()
Expand All @@ -17,19 +20,21 @@ func TestFetchUserInfo(t *testing.T) {
}

// Lat
if len(user.Lat) > 8 {
t.Errorf("Invalid Latitude. got: %v;", user.Lat)
lat, err := strconv.ParseFloat(user.Lat, 64)
if err != nil {
t.Errorf(err.Error())
}
if strings.Count(user.Lat, ".") != 1 {
t.Errorf("Invalid Latitude format. got: %v", user.Lat)
if lat < -90 || 90 < lat {
t.Errorf("Invalid Latitude. got: %v, expected between -90 and 90", user.Lat)
}

// Lon
if len(user.Lon) > 8 {
t.Errorf("Invalid Londitude. got: %v;", user.Lon)
lon, err := strconv.ParseFloat(user.Lon, 64)
if err != nil {
t.Errorf(err.Error())
}
if strings.Count(user.Lon, ".") != 1 {
t.Errorf("Invalid Londitude format. got: %v", user.Lon)
if lon < -180 || 180 < lon {
t.Errorf("Invalid Latitude. got: %v, expected between -90 and 90", user.Lon)
}

// Isp
Expand Down