File tree Expand file tree Collapse file tree 10 files changed +202
-19
lines changed Expand file tree Collapse file tree 10 files changed +202
-19
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ name : build-and-test 
3+ 
4+ " on " 
5+   push :
6+     branches :
7+       - main 
8+   pull_request :
9+ 
10+ jobs :
11+   build-and-test :
12+     name : build-and-test 
13+     runs-on : ubuntu-latest 
14+     steps :
15+       - uses : actions/checkout@v3 
16+ 
17+       - name : Set up Go 
18+         uses : actions/setup-go@v3 
19+         with :
20+           go-version : 1.19 
21+ 
22+       - name : Build 
23+         run : go build -v ./... 
24+ 
25+       - name : Test 
26+         run : go test -v ./... 
27+   golangci :
28+     name : lint 
29+     runs-on : ubuntu-latest 
30+     steps :
31+       - uses : actions/setup-go@v3 
32+         with :
33+           go-version : 1.19 
34+       - uses : actions/checkout@v3 
35+       - name : golangci-lint 
36+         uses : golangci/golangci-lint-action@v3 
Original file line number Diff line number Diff line change 1+ ---
2+ name : generic-linters 
3+ 
4+ " on " 
5+   push :
6+     branches :
7+       - main 
8+   pull_request :
9+ 
10+ 
11+ jobs :
12+   yamllint :
13+     runs-on : ubuntu-latest 
14+     steps :
15+       - name : Check out code 
16+         uses : actions/checkout@v3 
17+       - name : Run yaml Lint 
18+         uses : actionshub/yamllint@main 
19+ 
20+   mdl :
21+     runs-on : ubuntu-latest 
22+     steps :
23+       - name : Check out code 
24+         uses : actions/checkout@v3 
25+       - name : Run Markdown Lint 
26+         uses : actionshub/markdownlint@main 
Original file line number Diff line number Diff line change 1+ ---
2+ name : " Code Scanning - Action" 
3+ 
4+ " on " 
5+   push :
6+     branches :
7+       - main 
8+   pull_request :
9+     #  The branches below must be a subset of the branches above
10+     branches :
11+       - main 
12+   schedule :
13+     - cron : ' 0 17 * * 5' 
14+ 
15+ jobs :
16+   codeQL :
17+     #  CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
18+     runs-on : ubuntu-latest 
19+ 
20+     steps :
21+       - name : Checkout repository 
22+         uses : actions/checkout@v3 
23+         with :
24+           #  Must fetch at least the immediate parents so that if this is
25+           #  a pull request then we can checkout the head of the pull request.
26+           #  Only include this option if you are running this workflow on pull requests.
27+           fetch-depth : 2 
28+ 
29+       #  If this run was triggered by a pull request event then checkout
30+       #  the head of the pull request instead of the merge commit.
31+       #  Only include this step if you are running this workflow on pull requests.
32+       - run : git checkout HEAD^2 
33+         if : ${{ github.event_name == 'pull_request' }} 
34+ 
35+       #  Initializes the CodeQL tools for scanning.
36+       - name : Initialize CodeQL 
37+         uses : github/codeql-action/init@v2 
38+         #  Override language selection by uncommenting this and choosing your languages
39+         with :
40+           languages : ' go' 
41+ 
42+       - name : Set up Go 
43+         uses : actions/setup-go@v3 
44+         with :
45+           go-version : 1.19 
46+ 
47+       - name : Build 
48+         run : go build -v ./... 
49+ 
50+       - name : Perform CodeQL Analysis 
51+         uses : github/codeql-action/analyze@v2 
Original file line number Diff line number Diff line change 1+ rules "~MD013"
Original file line number Diff line number Diff line change 1+ ---
2+ extends: default
3+ rules:
4+   line-length:
5+     max: 256
6+     level: warning
7+   document-start: disable
8+   braces:
9+     forbid: false
10+     min-spaces-inside: 0
11+     max-spaces-inside: 1
12+     min-spaces-inside-empty: -1
13+     max-spaces-inside-empty: -1
Original file line number Diff line number Diff line change 1- # pointerhelpers  
1+ # pointer helpers  
22
33Go repo to hold all the helpers for pointers to save rewriting the same code every time
4- 
Original file line number Diff line number Diff line change 1+ package  pointerhelpers
2+ 
3+ // Int64Helper contains all Int64 related 
4+ // pointer helpers 
5+ type  Int64Helper  struct  {
6+ }
7+ 
8+ // Int64 returns a pointer to the int64 value passed in. 
9+ func  Int64 (v  int64 ) * int64  {
10+ 	return  & v 
11+ }
12+ 
13+ // Int64 returns a pointer to the int64 value passed in. 
14+ func  (i  * Int64Helper ) Int64 (v  int64 ) * int64  {
15+ 	return  Int64 (v )
16+ }
17+ 
18+ // Int64Value returns the value of the int64 pointer passed in or 
19+ // 0 if the pointer is nil. 
20+ func  Int64Value (v  * int64 ) int64  {
21+ 	if  v  !=  nil  {
22+ 		return  * v 
23+ 	}
24+ 	return  0 
25+ }
26+ 
27+ // Int64Value returns the value of the int64 pointer passed in or 
28+ // 0 if the pointer is nil. 
29+ func  (i  * Int64Helper ) Int64Value (v  * int64 ) int64  {
30+ 	return  Int64Value (v )
31+ }
Original file line number Diff line number Diff line change 1+ package  pointerhelpers
2+ 
3+ import  (
4+ 	"github.com/stretchr/testify/assert" 
5+ 	"testing" 
6+ )
7+ 
8+ func  TestInt (t  * testing.T ) {
9+ 	h  :=  StringHelper {}
10+ 	want  :=  "foo" 
11+ 	got  :=  h .String (want )
12+ 	assert .EqualValues (t , want , * got )
13+ }
14+ 
15+ func  TestStringValue (t  * testing.T ) {
16+ 	t .Run ("when nil returns empty string" , func (t  * testing.T ) {
17+ 		h  :=  StringHelper {}
18+ 		want  :=  "" 
19+ 		got  :=  h .StringValue (nil )
20+ 		assert .Equal (t , want , got )
21+ 	})
22+ 	t .Run ("when set returns the given string" , func (t  * testing.T ) {
23+ 		h  :=  StringHelper {}
24+ 		want  :=  "foobar" 
25+ 		got  :=  h .StringValue (String (want ))
26+ 		assert .Equal (t , want , got )
27+ 	})
28+ }
Original file line number Diff line number Diff line change @@ -5,26 +5,23 @@ import (
55	"testing" 
66)
77
8- // testify 
9- 
10- func  TestString (t  * testing.T ) {
11- 	h  :=  StringHelper {}
12- 	want  :=  "foo" 
13- 	got  :=  h .String (want )
8+ func  TestInt64 (t  * testing.T ) {
9+ 	h  :=  Int64Helper {}
10+ 	want  :=  int64 (42 )
11+ 	got  :=  h .Int64 (want )
1412	assert .EqualValues (t , want , * got )
1513}
1614
17- func  TestStringValue (t  * testing.T ) {
18- 	t .Run ("when nil returns empty string" , func (t  * testing.T ) {
19- 		h  :=  StringHelper {}
20- 		want  :=  "" 
21- 		got  :=  h .StringValue (nil )
22- 		assert .Equal (t , want , got )
15+ func  TestInt64Value (t  * testing.T ) {
16+ 	t .Run ("when nil returns 0" , func (t  * testing.T ) {
17+ 		h  :=  Int64Helper {}
18+ 		got  :=  h .Int64Value (nil )
19+ 		assert .Equal (t , int64 (0 ), got )
2320	})
24- 	t .Run ("when set returns the given string " , func (t  * testing.T ) {
25- 		h  :=  StringHelper {}
26- 		want  :=  "foobar" 
27- 		got  :=  h .StringValue ( String ( want ) )
28- 		assert .Equal (t , want , got )
21+ 	t .Run ("when set returns the given int64 " , func (t  * testing.T ) {
22+ 		h  :=  Int64Helper {}
23+ 		want  :=  h . Int64 ( int64 ( 42 )) 
24+ 		got  :=  h .Int64Value ( want )
25+ 		assert .Equal (t , * want , got )
2926	})
3027}
Original file line number Diff line number Diff line change @@ -4,4 +4,5 @@ package pointerhelpers
44// in this module to enable easier composition outside of this package 
55type  PointerHelper  struct  {
66	StringHelper 
7+ 	Int64Helper 
78}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments