Skip to content

Commit

Permalink
go_test記述、それを実行できるCIファイル記述
Browse files Browse the repository at this point in the history
  • Loading branch information
shari-sushi committed Jan 15, 2024
1 parent 860c5e9 commit 1fc0a56
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 15 deletions.
42 changes: 27 additions & 15 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
Explore-GitHub-Actions:

build:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.18'

# -v : パッケージ名を出力
- name: Build
run: go build -v ./...

# -v : テスト成功しても値を出力
- name: Test
run: go test -v ./...
23 changes: 23 additions & 0 deletions test0015Go/sample/test_ci/faunction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package test_ci

import (
"fmt"
)

func funReturnMes() string {
message := "起動確認"
fmt.Print(message)
return message
}

func funcRetunTwoTimes(i int) int {
fmt.Printf("x:%v", i)
return i * 2
}

func Parent() {
mes := funReturnMes()
x := 1
twoTimesInt := funcRetunTwoTimes(x)
fmt.Println("result", mes, twoTimesInt)
}
49 changes: 49 additions & 0 deletions test0015Go/sample/test_ci/faunction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package test_ci

import (
"testing"
)

func Test_funReturnMes(t *testing.T) {
tests := map[string]struct {
want string
expectErr bool
}{
"成功": {want: "起動確認", expectErr: false},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if got := funReturnMes(); got != tt.want {
t.Errorf("funReturnMes() = %v, want %v", got, tt.want)
}
})
}
}

func Test_funcRetunTwoTimes(t *testing.T) {
cases := map[string]struct {
i int
want int
expectErr bool
}{
"成功": {1, 2, false},
"失敗": {1, 1, true},
}
for testName, tt := range cases {
t.Run(testName, func(t *testing.T) {
if tt.expectErr == true {
if got := funcRetunTwoTimes(tt.i); got == tt.want {
t.Errorf("funcRetunTwoTimes() = %v, want %v", got, tt.want)
}
} else {
if got := funcRetunTwoTimes(tt.i); got != tt.want {
t.Errorf("funcRetunTwoTimes() = %v, not want %v", got, tt.want)
}
}
})
}
}

//////////////////////////////////////
// これをciで実行する
////////////////////////////////

0 comments on commit 1fc0a56

Please sign in to comment.