-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea79686
commit 57664e4
Showing
9 changed files
with
184 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.22" | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v -cover ./... |
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 |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
cover.html |
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
package excelsior_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/kakilangit/excelsior" | ||
"github.com/xuri/excelize/v2" | ||
) | ||
|
||
type nopResponseWriter struct{} | ||
|
||
func (nopResponseWriter) Header() http.Header { | ||
return http.Header{} | ||
} | ||
|
||
func (nopResponseWriter) Write([]byte) (int, error) { | ||
return 0, nil | ||
} | ||
|
||
func (nopResponseWriter) WriteHeader(int) {} | ||
|
||
func TestSerialize(t *testing.T) { | ||
data, err := excelsior.Serialize(func(file *excelize.File, style excelsior.Style) ([]byte, error) { | ||
const sheetName = "not found alphabet" | ||
|
||
excelsior.SetDefaultSheetName(file, sheetName) | ||
|
||
headers := []any{"alphabet"} | ||
data := nopSheetData{row: excelsior.Row{"a"}} | ||
|
||
sheet := excelsior.NewSheet(headers, excelsior.DefaultGetStyleFn, style.Header(), data) | ||
if err := sheet.Generate(file, sheetName); err != nil { | ||
return nil, err | ||
} | ||
|
||
return excelsior.Byte(file) | ||
}) | ||
|
||
if err != nil { | ||
t.Errorf("failed to serialize: %v", err) | ||
} | ||
|
||
if len(data) == 0 { | ||
t.Errorf("empty data") | ||
} | ||
} | ||
|
||
func TestSetHeader(t *testing.T) { | ||
header := http.Header{} | ||
excelsior.SetHeader(header, "test") | ||
|
||
if header.Get("Content-Disposition") != "attachment; filename=test.xlsx" { | ||
t.Errorf("failed to set header") | ||
} | ||
} | ||
|
||
func TestWriteByt(t *testing.T) { | ||
data := []byte("test") | ||
rw := nopResponseWriter{} | ||
err := excelsior.WriteByte(data, "test", rw) | ||
if err != nil { | ||
t.Errorf("failed to write byte: %v", err) | ||
} | ||
} |
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,63 @@ | ||
package excelsior_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kakilangit/excelsior" | ||
) | ||
|
||
type nopSheetData struct { | ||
row excelsior.Row | ||
} | ||
|
||
func (nopSheetData) Total() int { | ||
return 1 | ||
} | ||
|
||
func (d nopSheetData) Row(int) excelsior.Row { | ||
return d.row | ||
} | ||
|
||
func TestSheet(t *testing.T) { | ||
header := excelsior.Row{"Name", "Age"} | ||
getRowStyle := func(int) int { return 0 } | ||
headStyleID := 1 | ||
data := nopSheetData{row: excelsior.Row{"John Doe", 30}} | ||
s := excelsior.NewSheet(header, getRowStyle, headStyleID, data) | ||
|
||
if s.TotalColumn() != 2 { | ||
t.Errorf("TotalColumn() = %d; want 2", s.TotalColumn()) | ||
} | ||
|
||
if s.HeaderRow()[0] != "Name" { | ||
t.Errorf("HeaderRow()[0] = %s; want Name", s.HeaderRow()[0]) | ||
} | ||
|
||
if s.HeaderRow()[1] != "Age" { | ||
t.Errorf("HeaderRow()[1] = %s; want Age", s.HeaderRow()[1]) | ||
} | ||
|
||
if s.HeaderRowStyle()(0) != 1 { | ||
t.Errorf("HeaderRowStyle()(0) = %d; want 1", s.HeaderRowStyle()(0)) | ||
} | ||
|
||
if s.HeaderRowStyle()(1) != 1 { | ||
t.Errorf("HeaderRowStyle()(1) = %d; want 1", s.HeaderRowStyle()(1)) | ||
} | ||
|
||
if s.RowStyle()(0) != 0 { | ||
t.Errorf("RowStyle()(0) = %d; want 0", s.RowStyle()(0)) | ||
} | ||
|
||
if s.RowStyle()(1) != 0 { | ||
t.Errorf("RowStyle()(1) = %d; want 0", s.RowStyle()(1)) | ||
} | ||
|
||
if s.Row(0)[0] != "John Doe" { | ||
t.Errorf("Row(0)[0] = %s; want John Doe", s.Row(0)[0]) | ||
} | ||
|
||
if s.Row(0)[1] != 30 { | ||
t.Errorf("Row(0)[1] = %d; want 30", s.Row(0)[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