-
-
Notifications
You must be signed in to change notification settings - Fork 11
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 #29 from Shyam-Sundar-Raju/main
Modified folder structure and added unit test for issue#12
- Loading branch information
Showing
25 changed files
with
1,001 additions
and
300 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,39 @@ | ||
name: CI (Go Unit Tests) | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.23' | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run unit tests | ||
run: go test ./... -v | ||
|
||
- name: Go Lint Test | ||
uses: golangci/golangci-lint-action@v6.5.0 |
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,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"amrita_pyq/cmd/internal/configs" | ||
"amrita_pyq/cmd/internal/logo" | ||
"amrita_pyq/cmd/internal/menu" | ||
"amrita_pyq/cmd/internal/requestclient" | ||
"amrita_pyq/cmd/internal/webclient" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "ampyq", | ||
Short: "Amrita PYQ CLI", | ||
Long: `A CLI application to access Amrita Repository for previous year question papers.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Print(configs.LogoStyle.Render(logo.LOGO_ASCII)) | ||
cs := menu.CourseSelect{ | ||
ReqClient: requestclient.RequestClient{ | ||
WebClient: webclient.DefaultWebClient{}, | ||
}, | ||
} | ||
cs.ChooseCourse() | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := Cmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"testing" | ||
) | ||
|
||
func TestRoot(t *testing.T) { | ||
|
||
//Test RootCmd | ||
if _, ok := interface{}(Cmd).(*cobra.Command); !ok { | ||
t.Errorf("RootCmd is not of type *cobra.Command") | ||
} | ||
|
||
if Cmd.Use != "ampyq" { | ||
t.Errorf("Expected Use: 'ampyq', Got: %v", Cmd.Use) | ||
} | ||
|
||
if Cmd.Short != "Amrita PYQ CLI" { | ||
t.Errorf("Expected Short: 'Amrita PYQ CLI', Got: %v", Cmd.Short) | ||
} | ||
|
||
long := `A CLI application to access Amrita Repository for previous year question papers.` | ||
if Cmd.Long != long { | ||
t.Errorf("Expected Long: %q, Got: %v", long, Cmd.Long) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package configs | ||
|
||
import ( | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
const ( | ||
BASE_URL = "http://dspace.amritanet.edu:8080" | ||
COURSE_URL = BASE_URL + "/xmlui/handle/123456789/" | ||
COURSE_LIST_URL = COURSE_URL + "16" | ||
) | ||
|
||
// Styling for the logo and error messages. | ||
var ( | ||
LogoStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#01FAC6")). | ||
Bold(true) | ||
|
||
ErrorStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("9")). | ||
Bold(true). | ||
Underline(true). | ||
Padding(0, 1). | ||
Margin(1, 0, 1, 0). | ||
Border(lipgloss.RoundedBorder()). | ||
BorderForeground(lipgloss.Color("1")) | ||
|
||
FetchStatusStyle = lipgloss.NewStyle(). | ||
PaddingLeft(2). | ||
Foreground(lipgloss.Color("6")). | ||
Bold(true). | ||
Margin(1, 0) | ||
SelectionHistory []string | ||
) |
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,38 @@ | ||
package configs | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestConfigs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
url string | ||
wantUrl string | ||
}{ | ||
{ | ||
name: "SuccessBaseURLDeclaredProperly", | ||
url: BASE_URL, | ||
wantUrl: "http://dspace.amritanet.edu:8080", | ||
}, | ||
{ | ||
name: "SuccessCourseURLDeclaredProperly", | ||
url: COURSE_URL, | ||
wantUrl: "http://dspace.amritanet.edu:8080/xmlui/handle/123456789/", | ||
}, | ||
{ | ||
name: "SuccessCourseListURLDeclaredProperly", | ||
url: COURSE_LIST_URL, | ||
wantUrl: "http://dspace.amritanet.edu:8080/xmlui/handle/123456789/16", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
if tc.url != tc.wantUrl { | ||
t.Errorf("Expected %s, got %s", tc.wantUrl, tc.url) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cmd | ||
package logo | ||
|
||
const LOGO_ASCII string = ` | ||
__ __ _____ _____ _______ _______ ______ | ||
|
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,24 @@ | ||
package logo | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
const wantLogo = ` | ||
__ __ _____ _____ _______ _______ ______ | ||
/\ | \/ | __ \|_ _|__ __|/\ | __ \ \ / / __ \ | ||
/ \ | \ / | |__) | | | | | / \ | |__) \ \_/ / | | | | ||
/ /\ \ | |\/| | _ / | | | | / /\ \ | ___/ \ /| | | | | ||
/ ____ \| | | | | \ \ _| |_ | |/ ____ \ | | | | | |__| | | ||
/_/ \_\_| |_|_| \_\_____| |_/_/ \_\ |_| |_| \___\_\ | ||
` | ||
|
||
func TestLogo(t *testing.T) { | ||
t.Run("TestLogoASCII", func(t *testing.T) { | ||
t.Parallel() | ||
if LOGO_ASCII != wantLogo { | ||
t.Errorf("Expected %v, Received %v", wantLogo, LOGO_ASCII) | ||
} | ||
}) | ||
} |
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,89 @@ | ||
package menu | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"amrita_pyq/cmd/internal/requestclient" | ||
"amrita_pyq/cmd/util" | ||
|
||
"github.com/charmbracelet/huh" | ||
"github.com/charmbracelet/huh/spinner" | ||
|
||
"amrita_pyq/cmd/internal/configs" | ||
) | ||
|
||
type ( | ||
Subject struct { | ||
name string | ||
path string | ||
} | ||
|
||
CourseSelect struct { | ||
ReqClient requestclient.RequestClient | ||
} | ||
) | ||
|
||
func (cs *CourseSelect) ChooseCourse() { | ||
action := func() { | ||
time.Sleep(2 * time.Second) | ||
} | ||
if err := spinner.New().Title("Fetching Courses").Action(action).Run(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
resources, err := cs.ReqClient.GetCoursesReq(configs.COURSE_LIST_URL) | ||
if err != nil { | ||
fmt.Println(configs.ErrorStyle.Render(fmt.Sprintf("Error: %v\n", err))) | ||
os.Exit(1) | ||
} | ||
|
||
var selectedOption string | ||
var subjects []Subject | ||
var options []huh.Option[string] | ||
|
||
for _, res := range resources { | ||
subject := Subject{res.Name, res.Path} | ||
subjects = append(subjects, subject) | ||
options = append(options, huh.NewOption(subject.name, subject.name)) | ||
} | ||
options = append(options, huh.NewOption("Quit", "Quit")) | ||
|
||
// First menu does NOT display history yet | ||
form := huh.NewForm( | ||
huh.NewGroup( | ||
huh.NewSelect[string](). | ||
Title("Available Courses"). | ||
Options(options...). | ||
Value(&selectedOption), | ||
), | ||
) | ||
|
||
err = form.Run() | ||
if err != nil { | ||
fmt.Printf("Error: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Auto-exit if "Quit" is selected | ||
if selectedOption == "Quit" { | ||
util.QuitWithSpinner() | ||
} | ||
|
||
// Store only the selected course | ||
configs.SelectionHistory = []string{selectedOption} // Reset history to show only last selected | ||
|
||
// Move to the next menu (Second Menu) | ||
for _, subject := range subjects { | ||
if subject.name == selectedOption { | ||
url := configs.BASE_URL + subject.path | ||
semTable := SemTable{ | ||
ReqClient: cs.ReqClient, | ||
} | ||
semTable.ChooseQuestionSetFromSemester(url) | ||
break | ||
} | ||
} | ||
} |
Oops, something went wrong.